<?php
/* @var $this TaskController */
/* @var $model Task */
/* @var $form CActiveForm */
?>

<?php $form = $this->beginWidget('CActiveForm', array(
    'id' => 'task-form',
    'enableAjaxValidation' => false,
    'htmlOptions' => array(
        'role' => 'form',
        'class' => 'form-horizontal',
    )
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php if ($model->getErrors()) {
    ?>
    <div class="alert alert-error">
        <button class="close" data-dismiss="alert" type="button"> ×</button>
        <?php echo $form->errorSummary($model); ?>
    </div>
<?php } ?>
<div class="form admin-main-wrapper">
    <div class="block block-themed block-last">
        <div class="block-title">
            <h4></h4>
        </div>
        <div class="block-content">
            <div class="row control-group">
                <?php echo $form->labelEx($model, 'title', array('class' => 'control-label')); ?>
                <div class="controls">
                    <?php echo $form->textField($model, 'title', array('style' => 'width:49%')); ?>
                </div>
            </div>

            <div class="row control-group">
                <?php echo $form->labelEx($model, 'content', array('class' => 'control-label')); ?>
                <div class="controls">
                    <?php echo $form->textArea($model, 'content', array('style' => 'width:50%; height: 300px', 'id' => 'txtContent')); ?>
                </div>
            </div>

            <div class="row control-group">
                <?php echo $form->labelEx($model, 'note', array('class' => 'control-label')); ?>
                <div class="controls">
                    <?php echo $form->textArea($model, 'note', array('style' => 'width:50%; height: 300px')); ?>
                </div>
            </div>

            <?php if ($model->isNewRecord) { ?>
                <div class="row control-group day-wrapper">
                    <?php echo $form->labelEx($model, 'day', array('class' => 'control-label')); ?>
                    <div class="controls day-item" data-index="0">
                        <?php echo $form->dropDownList($model, 'day[]', array(
                            DayEnum::all => 'Tất cả các ngày',
                            DayEnum::monday => 'Thứ hai',
                            DayEnum::tuesday => 'Thứ ba',
                            DayEnum::wednesday => 'Thứ tư',
                            DayEnum::thursday => 'Thứ năm',
                            DayEnum::friday => 'Thứ sáu',
                            DayEnum::saturday => 'Thứ bảy',
                            DayEnum::sunday => 'Chủ nhật',
                        ), array('style' => 'width:50%')); ?>
                    </div>

                </div>
            <?php } ?>

            <?php if (isset($days) && count($days) > 0) { ?>

                <div class="row control-group day-wrapper">
                    <?php foreach ($days as $k => $day) { ?>
                        <?php echo $k == 0 ? $form->labelEx($model, 'day', array('class' => 'control-label')) : ""; ?>
                        <div class="controls day-item" data-index="<?php echo $k ?>">
                            <select name="Task[day][]">
                                <option <?php echo $day == DayEnum::all ? 'selected="selected"' : '' ?>
                                    value="<?php echo DayEnum::all ?>">
                                    Tất cả các ngày
                                </option>

                                <option <?php echo $day == DayEnum::monday ? 'selected="selected"' : '' ?>
                                    value="<?php echo DayEnum::monday ?>">
                                    Thứ hai
                                </option>

                                <option <?php echo $day == DayEnum::tuesday ? 'selected="selected"' : '' ?>
                                    value="<?php echo DayEnum::tuesday ?>">
                                    Thứ ba
                                </option>

                                <option <?php echo $day == DayEnum::wednesday ? 'selected="selected"' : '' ?>
                                    value="<?php echo DayEnum::wednesday ?>">
                                    Thứ tư
                                </option>

                                <option <?php echo $day == DayEnum::thursday ? 'selected="selected"' : '' ?>
                                    value="<?php echo DayEnum::thursday ?>">
                                    Thứ năm
                                </option>

                                <option <?php echo $day == DayEnum::friday ? 'selected="selected"' : '' ?>
                                    value="<?php echo DayEnum::friday ?>">
                                    Thứ sáu
                                </option>

                                <option <?php echo $day == DayEnum::saturday ? 'selected="selected"' : '' ?>
                                    value="<?php echo DayEnum::saturday ?>">
                                    Thứ bảy
                                </option>

                                <option <?php echo $day == DayEnum::sunday ? 'selected="selected"' : '' ?>
                                    value="<?php echo DayEnum::sunday ?>">
                                    Chủ nhật
                                </option>

                            </select>

                        </div>
                    <?php } ?>

                </div>
            <?php } ?>


            <div class="row control-group">
                <div class="control-label">

                </div>
                <div class="controls more-day">
                    <label style="cursor: pointer"> Thêm ngày</label>
                </div>
            </div>

            <div class="row control-group">
                <?php echo $form->labelEx($model, 'user_id', array('class' => 'control-label')); ?>
                <div class="controls">
                    <?php echo $form->dropDownList($model, 'user_id', CHtml::listData($users, 'id', 'name'), array('style' => 'width:50%')); ?>
                </div>
            </div>

            <div class="row control-group buttons">
                <div class="controls">
                    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class' => 'btn btn-default')); ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->endWidget(); ?>
<script type="text/javascript">
    var $base = "<?php echo HSUrl::home()?>";
    bkLib.onDomLoaded(function () {
        new nicEditor({
            iconsPath: $base + '/images/nicEditorIcons.gif',
            fullPanel: true}).panelInstance('txtContent');
    });
    $(document).ready(function () {
        $('.more-day').click(function () {
            var $html = '<div class="controls day-item" style="width: 50%">';
            $html += $(".day-item[data-index=0]").html();
            $html += "</div>";
            $(".day-wrapper").append($html);
        });

    });
</script>